package shop.up.product.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import shop.up.common.result.Result;
import shop.up.model.product.BaseSaleAttr;
import shop.up.model.product.SpuInfo;
import shop.up.product.service.ManageService;

import javax.annotation.Resource;
import java.util.List;

/**
 * Spu信息
 *
 * @author zzc
 * @date 2023/3/29 14:13
 */
@Api(tags = "商品基本信息控制器")
@RestController
@RequestMapping("admin/product")
public class SpuManageController {

    @Resource
    private ManageService manageService;

    /**
     * 分页查询商品基本信息
     *
     * @return
     */
    @ApiOperation("分页查询")
    @GetMapping("{page}/{limit}")
    public Result getSpuInfoList(@PathVariable("page") Long page,
                                 @PathVariable("limit") Long limit,
                                 SpuInfo spuInfo) {
        Page<SpuInfo> spuInfoPage = new Page<>(page, limit);
        IPage<SpuInfo> spuInfoPage1 = manageService.getSpuInfoPage(spuInfoPage, spuInfo);
        return Result.ok(spuInfoPage1);
    }

    /**
     * 查询所有的商品销售属性集合
     *
     * @return
     */
    @ApiOperation("查询所有的销售属性集合")
    @GetMapping("baseSaleAttrList")
    public Result baseSaleAttrList() {
        List<BaseSaleAttr> baseSaleAttrList = manageService.getBaseSaleAttrList();
        return Result.ok(baseSaleAttrList);
    }

    /**
     * 保存spu
     *
     * @param spuInfo
     * @return
     */
    @ApiOperation("保存spu")
    @PostMapping("saveSpuInfo")
    public Result saveSpuInfo(@RequestBody SpuInfo spuInfo) {
        // 调用服务层的保存方法
        manageService.saveSpuInfo(spuInfo);
        return Result.ok();
    }


}
